package Lee_code;

import java.util.Deque;
import java.util.LinkedList;

public class Lee_844 {
    public boolean backspaceCompare(String s, String t) {
        Deque<Character> stack1 = new LinkedList<>();
        Deque<Character> stack2 = new LinkedList<>();

        for (char c : s.toCharArray())
        {
            if(c == '#' && !stack1.isEmpty())
                stack1.pop();
            else if(c != '#')
                stack1.push(c);
        }

        for (char c : t.toCharArray())
        {
            if(c == '#' && !stack2.isEmpty())
                stack2.pop();
            else if(c != '#')
                stack2.push(c);
        }

        // 比较两个栈
        return stack1.equals(stack2);
    }
}
